﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Public.Web.Areas.Membership.Controllers
{
    [Authorize]
    [EnsureSsl]
    public class DonationsController : Controller
    {
        [AppendLayoutViewModel]
        public ActionResult Index()
        {
            string token = User.Identity.Name;
            var model = Adams.Public.Web.Business.Web.Areas.Membership.Donations.Index.PageLoad(token);
            return View(model);
        }

        [AppendLayoutViewModel]
        public ActionResult Donate(string b)
        {
            string token = User.Identity.Name;
            var model = Adams.Public.Web.Business.Web.Areas.Membership.Donations.Donate.PageLoad(b, token);
            
            if (!model.HasValidCreditCard)
            {
                return Redirect("/MyAdams/Profile/CreditCard?r=1");
            }

            return View(model);
        }


        public JsonResult SaveDonation(Adams.Public.DataTransfer.Web.Areas.Membership.Donations.Donate.FormInput input)
        {
            input.Token = User.Identity.Name;
            var model = Adams.Public.Web.Business.Web.Areas.Membership.Donations.Donate.SaveDonation(input);
            return Json(model);
        }

        public JsonResult CancelDonation(Adams.Public.DataTransfer.Web.Areas.Membership.Donations.Index.CancelInput input)
        {
            input.Token = User.Identity.Name;
            var model = Adams.Public.Web.Business.Web.Areas.Membership.Donations.Index.CancelDonation(input);
            return Json(model);
        }

        public JsonResult CancelRecurringDonation(Adams.Public.DataTransfer.Web.Areas.Membership.Donations.Index.CancelRecurringInput input)
        {
            input.Token = User.Identity.Name;
            var model = Adams.Public.Web.Business.Web.Areas.Membership.Donations.Index.CancelRecurringDonation(input);
            return Json(model);
        }

        [AppendLayoutViewModel]
        public ActionResult Confirm(string d, string r)
        {
            string token = User.Identity.Name;
            var model = Adams.Public.Web.Business.Web.Areas.Membership.Donations.Confirm.PageLoad(d, r, token);
            return View(model);
        }

        public JsonResult ConfirmDonation(Adams.Public.DataTransfer.Web.Areas.Membership.Donations.Confirm.FormInput input)
        {
            input.Token = User.Identity.Name;
            var model = Adams.Public.Web.Business.Web.Areas.Membership.Donations.Confirm.ConfirmDonation(input);
            return Json(model);
        }

        [AppendLayoutViewModel]
        public ActionResult ThankYou()
        {
            return View();
        }
    }
}
